cmake_minimum_required(VERSION 2.8)

#配置交叉编译工具链，不配置就采用默认的gcc编译
#SET(CMAKE_C_COMPILER "/home/zhangk/toolchain/toolchain-aarch64_cortex-a53_gcc-8.3.0_musl/bin/aarch64-openwrt-linux-gcc")

#主机gcc
#SET(CMAKE_C_COMPILER "/usr/bin/gcc")
#fuxi
#SET(CMAKE_C_COMPILER "/opt/csky-toolchain/bin/csky-abiv2-linux-gcc")
#生成的可执行文件的名称
PROJECT(appctl)

IF(NOT DEFINED EGW_SOURCES_ROOT)
	SET(EGW_SOURCES_ROOT "./")
ENDIF(NOT DEFINED EGW_SOURCES_ROOT)

#配置安装路径
IF(NOT DEFINED EGW_INSTALL_ROOT)
	SET(EGW_INSTALL_ROOT "./build/out/")
ENDIF(NOT DEFINED EGW_INSTALL_ROOT)

GET_FILENAME_COMPONENT(EGW_SOURCES_ROOT "${EGW_SOURCES_ROOT}" ABSOLUTE)
GET_FILENAME_COMPONENT(EGW_INSTALL_ROOT "${EGW_INSTALL_ROOT}" ABSOLUTE)

#要编译的.c文件
FILE(GLOB_RECURSE SOURCES  	
    "${EGW_SOURCES_ROOT}/src/common/*.c"
    "${EGW_SOURCES_ROOT}/src/log_manage/*.c"
	"${EGW_SOURCES_ROOT}/src/app_action/*.c"
	"${EGW_SOURCES_ROOT}/src/main/*.c"
	
	)

#头文件的路径
INCLUDE_DIRECTORIES(
	${EGW_SOURCES_ROOT}/src/common
	${EGW_SOURCES_ROOT}/src/log_manage
	${EGW_SOURCES_ROOT}/src/app_action
    ${EGW_SOURCES_ROOT}/src/main
	${EGW_SOURCES_ROOT}/include
    ${EGW_SOURCES_ROOT}/lib
)

#给当前工程链接需要的库文件
link_libraries(pthread)

#添加需要链接的库文件目录
link_directories(
    ${EGW_SOURCES_ROOT}/lib
	${EGW_SOURCES_ROOT}/lib/mqtt
)

##为给定的目标设置链接时使用的库
##target_link_libraries(server libopen62541.a)

ADD_EXECUTABLE(${PROJECT_NAME}  ${SOURCES} )

#编译完后要安装到的地方
INSTALL(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${EGW_INSTALL_ROOT})

##设置C编译参数
#O0 ->O1->O2->O3 O0表示不优化
#-Wall生成警告信息
#-g生成调试信息
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -Wall")

#设置C++编译参数
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 -Wall")

# ---  输出目标路径
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/target/${PLATFORM_NAME})
message("Set target to ${EXECUTABLE_OUTPUT_PATH}")

set(CMAKE_VERBOSE_MAKEFILE ON)